package com.lun.swordtowardoffer2.c01;

public class SingleNumberInThreeArray {
	
	public static final int INTEGER_BIT_TOTAL_NUM = 32;
	
	public int findSingleNumber(int[] array) {
		int[] bitCount = new int[INTEGER_BIT_TOTAL_NUM];
		int result = 0;
		
		for(int num : array) {
			for(int i = 0; i < INTEGER_BIT_TOTAL_NUM; i++) {
				//数从最左边数位开始数，这样为下一步for循环中复原结果作准备
				bitCount[i] += (num >>> (INTEGER_BIT_TOTAL_NUM - 1 - i)) & 1;
			}
		}
		
		for(int i = 0; i < INTEGER_BIT_TOTAL_NUM; i++) {
			result = (result << 1) + bitCount[i] % 3;
		}
		
		return result;
	}
}
